package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.City;
import cn.kgc.springcloud.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2023/1/11
 */
@RestController
@RequestMapping("city")
public class CityController {

    @Autowired
    private CityService cityService;

    @GetMapping
    public List<City> cityList(){
        List<City> list = cityService.list();
        return list;
    }

    @PostMapping
    public City addCity(City city){
        cityService.save(city);
        return city;
    }

    @GetMapping("{id}")
    public City getById(@PathVariable Integer id){
        return  cityService.getById(id);
    }
}
